modname ?= 

arch ?= x86
ifeq ($(arch),x86)
	KERNELDIR := /lib/modules/$(shell uname -r)/build
	CROSS_COMPILE := 
else
	KERNELDIR := /home/linux/linux-stm32mp-5.10.61-stm32mp-r2-r0/linux-5.10.61/
	CROSS_COMPILE := arm-linux-gnueabihf-
endif

CURRENTDIR := $(shell pwd)

CC := $(CROSS_COMPILE)gcc
all:
	make -C $(KERNELDIR) M=$(CURRENTDIR) modules
	$(CC) test.c -o test
install:
	@cp *.ko  ~/nfs/rootfs/ 
	@cp test ~/nfs/rootfs

help:
	@echo "make arch=arm|x86 modname=modules drivers source file name"

clean:
	make -C $(KERNELDIR) M=$(CURRENTDIR) clean
	rm test
 
obj-m := $(modname).o